package com.no.hq.controller;

import com.no.hq.pojo.User;
import com.no.hq.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.sql.DataSource;

@Controller
@RequestMapping
public class HelloController {

    @Autowired
    private DataSource dataSource;

    @GetMapping("hello")
    @ResponseBody
    public String hello() {
        System.out.println("dataSource -> " + dataSource);
        return "Hello, Spring Boot!";
    }

    @Autowired
    private UserService userService;

    @GetMapping("user/{id}")
    @ResponseBody
    public User user(@PathVariable Long id) {
        return userService.queryById(id);
    }

    @GetMapping("index")
    public String index() throws Exception {
        System.out.println("罗启倩改");
        return "index";
        // 注释掉以下为了演示错误处理用的代码块
        /*try {
            System.out.println(5/0);
        } catch (Exception e) {
            e.printStackTrace();
            throw new Exception("扔个异常看看");
        }
        return "index";*/
    }
    public void f1(){
        System.out.println("李辉提交了");
    }
    public static void a1(){
        System.out.println("====================");
    }
}
